//
//  OrderStaffSelectCell.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/20.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "OrderStaffSelectCell.h"

@interface OrderStaffSelectCell()
@end

@implementation OrderStaffSelectCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if( !self ) {
        return nil;
    }
    [self initSubView:frame];
    return self;
}

-(void)initSubView:(CGRect)frame{
    CGSize mobileSize = [@"18788767866" sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:TextFontSizeH3]}];
    CGFloat y = (42 - mobileSize.height) / 2;
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.font = [UIFont systemFontOfSize:TextFontSizeH3];
    self.nameLabel.textColor = TextColorDefault;
    self.nameLabel.frame = CGRectMake(kOrderCellSpacing+3, y, mobileSize.width * 0.75, mobileSize.height);
    [self addSubview:self.nameLabel];
    
    self.mobileLabel = [[UILabel alloc] init];
    self.mobileLabel.font = [UIFont systemFontOfSize:TextFontSizeH3];
    self.mobileLabel.textColor = TextColorDefault;
    self.mobileLabel.frame = CGRectMake((frame.size.width - mobileSize.width) / 2, y, mobileSize.width, mobileSize.height);
    [self addSubview:self.mobileLabel];
    
    self.checkBtn = [[UIButton alloc] init];
    [self.checkBtn setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
    [self.checkBtn setImage:[UIImage imageNamed:@"check_on"] forState:UIControlStateSelected];
    self.checkBtn.frame = CGRectMake(frame.size.width - kOrderCellSpacing - 38, 8, 27, 27);
    [self addSubview:self.checkBtn];
    
    [self.checkBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)btnClick:(id)sender {
    [self.checkBtn setSelected:true];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"selectStaff" object:self userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%lu", (unsigned long)self.staffID] forKey:@"staffID"]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

-(void)setStaff:(JFBStaffDS *)staff{
    self.nameLabel.text = staff.name;
    self.mobileLabel.text = staff.telephone;
    self.staffID = staff.Id;
    
    if( staff.isDefault) {
    
        [self.checkBtn setSelected:true];
//        [self.checkBtn setImage:[UIImage imageNamed:@"check_on"] forState:UIControlStateNormal];
    }
}

@end
